<extend name="Common@Layout:hui-admin" />
<block name="title"><title>Administator管理后台</title></block>
<block name="style">
</block>

<block name="main">
	<nav class="breadcrumb">
		<i class="Hui-iconfont"></i>
		 首页 <span class="c-gray en">&gt;</span>
		 管理员管理 <span class="c-gray en">&gt;</span>  
		权限管理 
		<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a>
	</nav>
	<div class="pd-20">
		<div class="cl pd-5 bg-1 bk-gray"> 
			<div class="btn-group l mr-20">
				<select class="input-text" style="width:auto;" id="changeG">
					<php>$groups = C('AUTH_MINI_GROUP');</php>
					<volist name="groups" id="vo">
						<option value="{$vo}" <eq name="auth_group" value="$vo">selected</eq>>{$vo}</eq>
					</volist>
				</select>
			</div>
			<span class="r"></span>
		</div>
		<table class="table">
			<tr>
				<td width="200" class="va-t">
					<div class="mb-10">
						操作：
						<div class="btn-group">
							<a <if condition='$_SESSION["cur_auth_action"] eq "add"'>_</if>href="{:U('Authadmin/index','action=add')}" class="btn btn-default <if condition='$_SESSION["cur_auth_action"] eq "add"'>btn-primary</if> radius">添加</a>
						  	<a <if condition='$_SESSION["cur_auth_action"] eq "edit"'>_</if>href="{:U('Authadmin/index','action=edit')}" class="btn btn-default <if condition='$_SESSION["cur_auth_action"] eq "edit"'>btn-primary</if> radius">编辑</a>
						  	<a <if condition='$_SESSION["cur_auth_action"] eq "del"'>_</if>href="{:U('Authadmin/index','action=del')}" class="btn btn-default <if condition='$_SESSION["cur_auth_action"] eq "del"'>btn-primary</if> radius">删除</a>
						</div>
					</div>
					<ul id="treeDemo" class="ztree"></ul>
				</td>
				<td class="va-t"><IFRAME ID="testIframe" Name="testIframe" FRAMEBORDER=0 SCROLLING=AUTO width=100%  height=450px SRC="{:u('Authadmin/edit')}"></IFRAME></td>
			</tr>
		</table>
		
	</div>
</block>

<block name="script">
<script type="text/javascript">
$('#changeG').change(function(){
	var g = $(this).val();
	window.location.href="/users/authadmin/index/group/"+g+".html"; 
});
var cur_action = '{$_SESSION["cur_auth_action"]}';

var setting = {
	view: {
		dblClickExpand: false,
		showLine: false,
		selectedMulti: false
	},
	data: {
		simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			rootPId: ""
		}
	},
	callback: {
		beforeClick: function(treeId, treeNode) {
			var zTree = $.fn.zTree.getZTreeObj("tree");
			if (treeNode.isParent) {
				//zTree.expandNode(treeNode);
				//return false;
			} 
			var url = '/users/authadmin/edit' ;
			if(cur_action == 'add'){
				url = url + '/parentid/'+treeNode.id;
				demoIframe.attr("src",url);
			}
			if(cur_action == 'edit'){
				url = url + '/id/'+treeNode.id;
				demoIframe.attr("src",url);
			}
			if(cur_action == 'del'){
				var asker = layer.confirm('确定删除吗？', function(){
					var ii = layer.msg('数据处理中...', {icon: 16,time: 10000}, function(){
			    	    layer.alert('服务器响应超时', {icon: 7});
			    	});
					$.get('/users/authadmin/del/ids/'+treeNode.id,function(data){
						layer.close(ii);
						//data = JSON.parse(data);  //str 转 json
						if(data.status){
							layer.msg('删除成功', {icon: 1,time:1000},function(){
							    location.reload(); //自动关闭后可做一些刷新页面等操作
							});
						}else{
							layer.msg(data.info, {icon: 2,time:1000});
						}
					},'json');
				});
			}
			return true;
			
		}
	}
};
		
var code;
		
function showCode(str) {
	if (!code) code = $("#code");
	code.empty();
	code.append("<li>"+str+"</li>");
}
		
$(document).ready(function(){
	
});
function shuaxin_nodes(){

	$.post('/users/authadmin/ajax_nodes',function(res){
		//alert(res[0]);
		var t = $("#treeDemo");
		t = $.fn.zTree.init(t, setting,res );
		demoIframe = $("#testIframe");
		demoIframe.bind("load", loadReady);
		var zTree = $.fn.zTree.getZTreeObj("tree");
		zTree.selectNode(zTree.getNodeByParam("id",'11'));
	});

}
</script>
</block>